package com.xjgzinfo.usdp.service.impl;

import com.xjgzinfo.usdp.domain.BladeVisualCategory;
import com.xjgzinfo.usdp.repository.BladeVisualCategoryRepository;
import com.xjgzinfo.usdp.service.BladeVisualCategoryService;
import com.xjgzinfo.usdp.service.dto.BladeVisualCategoryDTO;
import com.xjgzinfo.usdp.service.mapper.BladeVisualCategoryMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

/**
 * Service Implementation for managing {@link BladeVisualCategory}.
 */
@Service
@Transactional
public class BladeVisualCategoryServiceImpl implements BladeVisualCategoryService {

    private final Logger log = LoggerFactory.getLogger(BladeVisualCategoryServiceImpl.class);

    private final BladeVisualCategoryRepository bladeVisualCategoryRepository;

    private final BladeVisualCategoryMapper bladeVisualCategoryMapper;

    public BladeVisualCategoryServiceImpl(BladeVisualCategoryRepository bladeVisualCategoryRepository, BladeVisualCategoryMapper bladeVisualCategoryMapper) {
        this.bladeVisualCategoryRepository = bladeVisualCategoryRepository;
        this.bladeVisualCategoryMapper = bladeVisualCategoryMapper;
    }

    @Override
    public BladeVisualCategoryDTO save(BladeVisualCategoryDTO bladeVisualCategoryDTO) {
        log.debug("Request to save BladeVisualCategory : {}", bladeVisualCategoryDTO);
        BladeVisualCategory bladeVisualCategory = bladeVisualCategoryMapper.toEntity(bladeVisualCategoryDTO);
        bladeVisualCategory = bladeVisualCategoryRepository.save(bladeVisualCategory);
        return bladeVisualCategoryMapper.toDto(bladeVisualCategory);
    }

    @Override
    @Transactional(readOnly = true)
    public Page<BladeVisualCategoryDTO> findAll(Pageable pageable) {
        log.debug("Request to get all BladeVisualCategories");
        return bladeVisualCategoryRepository.findAll(pageable)
                .map(bladeVisualCategoryMapper::toDto);
    }


    @Override
    @Transactional(readOnly = true)
    public Optional<BladeVisualCategoryDTO> findOne(Long id) {
        log.debug("Request to get BladeVisualCategory : {}", id);
        return bladeVisualCategoryRepository.findById(id)
                .map(bladeVisualCategoryMapper::toDto);
    }

    @Override
    public void delete(Long id) {
        log.debug("Request to delete BladeVisualCategory : {}", id);
        bladeVisualCategoryRepository.deleteById(id);
    }
}
